#include<stdio.h>
#include<malloc.h>
typedef struct LNode{
	int data;
	struct LNode* next;
}LNode,*LinkList;

void out(LinkList H){
	if(H->next){
		LinkList p;
		p=H->next;
		while(p){
			printf("%d",p->data);
			if(p->next != NULL) 
            printf(" ");
			p = p->next;
		}
		printf("\n");
	}
	else printf("NULL");
}

LinkList Creat_List(){
	LinkList H,node,end;
	int x;
	H = (LinkList)malloc(sizeof(LNode));
	H->next = NULL;
	end = H;
	while(scanf("%d",&x) && x!=-1){
		node = (LinkList)malloc(sizeof(LNode));
		node->next=NULL;
		
		node->data = x;
		end->next = node;
		end = node;
	}
	return H; 
}

LinkList jiaoji(LinkList A,LinkList B)
{
    LinkList c=NULL,ptr=NULL,tail=NULL,ptr1=NULL,ptr2=NULL;
    ptr1=A;
    ptr2=B;
    while(ptr1!=NULL&&ptr2!=NULL)
    {
        if(ptr1->data<ptr2->data) 
        ptr1=ptr1->next;
        else if(ptr1->data>ptr2->data)
        ptr2=ptr2->next;
        else if(ptr1->data==ptr2->data)
        {
            ptr=(LinkList)malloc(sizeof(LNode));
            ptr->data=ptr1->data;
            ptr->next=NULL;
            if(c==NULL) c=ptr;
            else tail->next=ptr;
            tail=ptr;
            ptr1=ptr1->next;
            ptr2=ptr2->next;
        }
    }
    return c;
}
int main()
{
	LinkList A,B,C;
	A = Creat_List();
	B = Creat_List();
	C = jiaoji(A,B);
	out(C);
    return 0;
}
//两个有序链表序列的交集